import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

public class UseJson {
    public static void main(String[] args) throws IOException {
        System.out.println(System.getProperty("user.dir"));
        House[] houses = new House[]{
                new House("1111", new BigDecimal(1111)),
                new House("2222", new BigDecimal(2222)),
                new House("3333", new BigDecimal(3333)),
        };
        User user = new User("litter hot",new BigDecimal(1111111),44,new String[]{"red","yellow"},houses,new Date());

        //然后我们引入一些jack的对应的包，进行转换，哦~伟大的jack啊
        ObjectMapper objectMapper=new ObjectMapper();
        String userStr = objectMapper.writeValueAsString(user);
        System.out.println(userStr);
        System.out.println(objectMapper.readValue(userStr,User.class));

        //创建个写入流把数据写入把
        FileOutputStream fileOutputStream=new FileOutputStream(".\\userStr.txt");
        byte[] userStrBytes=userStr.getBytes();
        fileOutputStream.write(userStrBytes);
        fileOutputStream.flush();
        fileOutputStream.close();
    }
}


@Data
@NoArgsConstructor
@AllArgsConstructor
class User {
    String name;
    BigDecimal money;
    int age;
    String[] likeColor;
    House[] houses;
    Date birthday;
}


@Data
@NoArgsConstructor
@AllArgsConstructor
class House {
    String address;
    BigDecimal price;
}

